﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace SpecF.ExpressionVisitors
{
    public class ExpressionParser : ExpressionVisitor
    {
        List<string> properties;

        public ExpressionParser()
        {
            properties = new List<string>();
        }

        public List<string> Parse(Expression expression)
        {
            properties.Clear();
            Visit(expression);
            return properties;
        }
        protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
        {
            properties.Add(methodCallExpression.Method.Name);
            return base.VisitMethodCall(methodCallExpression);
        }

        protected override Expression VisitMember(MemberExpression memberExpression)
        {
            properties.Add(memberExpression.Member.Name);
            return base.VisitMember(memberExpression);
        }
    }

}
